#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 1e4 +5;
int arr[maxn];
int ad[105];
int cnt_cmp;
int cnt_swp;

void pttion(int n, int stp){
	for (int i=stp+1;i<=n;i++) {
		int val = arr[i];
		int cur = i;
		while (cur > stp && ++cnt_cmp && arr[cur-stp] > val) {
			arr[cur] = arr[cur-stp]; // 往后挪
			cur -= stp;
			cnt_swp++;
		}
		// 填入到正确的位置
		arr[cur] = val;	
	}
}


void solve(){
	int n, m;
	cin >> n >> m;
	for (int i=1;i<=m;i++) {
		cin >> ad[i];
	}
	for (int i=1;i<=n;i++) {
		cin >> arr[i];
	}
	for (int i=1;i<=m;i++) {
		pttion(n, ad[i]); // n 个数, 增量是 ad[i];		
	}
	cout << cnt_cmp << " " << cnt_swp; 
}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}
